<?php
class Ad_status_editAction extends CAction{
	
	public function run(){
		$ad_model = $this->editAuth();
		if(isset($_GET['status']))
		{
			$status = $_GET['status'];
			$ad_model->status = Ad::converStatus($status);
			if($ad_model->update(array('status'))){
				echo json_encode(array('Ad'=>array('status'=>$status)));
			}else{
				echo json_encode(array('error'=>Yii::t('adv','error_edit_auth')));
			}
			Yii::app()->end();
		}
		$this->getController()->layout = false;
		$this->getController()->render('status',array('ad_id'=>$ad_model->id));
	}
	
	public function editAuth()
	{
		if(isset($_GET['ad_id']))
		{
			$ad_model = Ad::model()->findByPk($_GET['ad_id']);
			if($ad_model===null || $ad_model->status == Ad::STATUS_PENDING || $ad_model->status == Ad::STATUS_STOPPED){
				//echo json_encode(array('error'=>Yii::t('adv','error_edit_auth')));
				Yii::app()->end();
			}
			return $ad_model;
		}else{
			throw new CHttpException(404,'The requested page does not exist.');
		}
	}
}



		